package it.koutifaris.travianmap.gui;

import it.koutifaris.travianmap.model.Tribe;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Matrix;

class MapImageFactory {

	private Bitmap village[] = new Bitmap[Tribe.values().length];
	private int sqDim;

	public MapImageFactory(int sqDim) {
		this.sqDim = sqDim;
	}

	public static MapImageFactory getInstance(int sqDim) {
		return new MapImageFactory(sqDim);
	}

	public Bitmap getVillageBmp(Resources res, Tribe race) {
		if (village[race.ordinal()] == null) {
			Bitmap tmp = ImageFactory.getVillage(res, race);
			Matrix matrix = new Matrix();
			float scaleX = (float) sqDim / tmp.getWidth();
			float scaleY = (float) sqDim / tmp.getHeight();
			matrix.postScale(scaleX, scaleY);
			village[race.ordinal()] = Bitmap.createBitmap(tmp, 0, 0, tmp.getWidth(), tmp.getHeight(), matrix, true);
		}
		return village[race.ordinal()];
	}

	public void setSqDim(int sqDim) {
		for (int i = 0; i < village.length; i++)
			village[i] = null;
		this.sqDim = sqDim;
	}

}
